package com.gsafety.spring;

import com.gsafety.spring.bean.Student;
import com.gsafety.spring.service.StudentService;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

/*
    针对于数据库事务的操作：

    setCommit(false);

    target.method(); [1.执行成功； 2.执行失败]

    conn.commit();
    or
    conn.rollback();


 */
public class SpringClientTransaction {
    public static void main(String[] args) {
        Resource resource =  new ClassPathResource("applicationContext3.xml");
        DefaultListableBeanFactory defaultListableBeanFactory = new DefaultListableBeanFactory();

        BeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(defaultListableBeanFactory);

        beanDefinitionReader.loadBeanDefinitions(resource);

        StudentService studentService =  (StudentService) defaultListableBeanFactory.getBean("studentServiceProxy");

        Student student = new Student();
        student.setName("zhangsan");
        student.setAge(20);

        studentService.saveStudent(student);
    }
}
